package com.eastidea.live.servlet;

import java.util.Locale;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringUtil implements ApplicationContextAware {

	public static ApplicationContext appContext;

	public SpringUtil() {
	}

	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		appContext = applicationContext;
	}

	public static String getMessage(String key, Object params[]) {
		return getMessage(key, params, Locale.ENGLISH);
	}

	public static String getMessage(String key, Object params[], Locale locale) {
		return appContext.getMessage(key, params, locale);
	}

	public static Object getBean(String serviceName) {
		Object obj = new Object();
		try {
			obj = appContext.getBean(serviceName);
		} catch (BeansException e) {
			e.printStackTrace();
			return null;
		}
		return obj;
	}
}
